import org.junit.Test;
import static org.junit.Assert.*;
public class NGuessNumberTest {
    @org.junit.Test
    public void main() {
        generateAnswerTest();
        getPlayerInputTest();
        compareGuessAnswerTest();
        isWinTest();
    }

    public void generateAnswerTest() {
        int a = 4;
        NGuessNumber nGuessNumber = new NGuessNumber();
        assertEquals(a,nGuessNumber.generateAnswer().length);
        System.out.println("答案数字数量为4");

        int num [] = nGuessNumber.generateAnswer();
        boolean flag_1 = false;
        boolean flag_2 = false;

        for (int i=0; i<a; i++){
            if(num[i]>=0&&num[i]<=9){
                flag_1=true;
            }else{
                flag_1=false;
            }
            for (int j=0; j<=i; j++){
                if(i!=j) {
                    if (num[i] == num[j]) {
                        flag_2 = false;
                    } else {
                        flag_2 = true;
                    }
                }
            }
        }

        assertEquals(true,flag_2);
        System.out.println("其中无重复数字");

        assertEquals(true,flag_1);
        System.out.println("数字都在0-9之间");
        }

    @Test
    public void getPlayerInputTest(){
        int num= 4;
        NGuessNumber nGuessNumber = new NGuessNumber();
        assertEquals(num,nGuessNumber.generateAnswer().length);
        System.out.println();
        System.out.println("玩家输入数字数量为4");
    }

    @Test
    public void compareGuessAnswerTest() {
        NGuessNumber nGuessNumber = new NGuessNumber();
        int[] num = nGuessNumber.generateAnswer();
        int[] guessList = nGuessNumber.guesslist;
        int a = 0;
        int b = 0;
        for (int i = 0; i < num.length; i++) {
            for (int j = 0; j < guessList.length; j++) {
                if (i == j) {
                    if (num[i] == guessList[j]) {
                        a++;
                    }
                } else {
                    if (num[i] == guessList[j]) {
                        b++;
                    }
                }
            }
        }
        String ti = "位置和数字都猜对的有"+a+"个 位置不相同但数字猜对的有"+b+"个";

        assertEquals(ti,nGuessNumber.compareGuessAnswer());

        System.out.println("比较答案测试通过");
    }

    @Test
    public void isWinTest(){
        NGuessNumber nGuessNumber = new NGuessNumber();
        boolean flag = false;

        if (nGuessNumber.a==4){
            flag=true;
            assertEquals(flag,nGuessNumber.isWin());
            System.out.println("t通过");
        }else {
            flag=false;
            assertEquals(flag,nGuessNumber.isWin());
            System.out.println("f通过");
        }
    }

}
